﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace MobileManager
{
    public partial class UserInfoModify : System.Web.UI.Page
    {
        private MM.Model.T_Users userModel;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["CurUser"] == null)
            {
                Response.Redirect("Login.aspx");
                return;
            }
            else
            {
                userModel = (MM.Model.T_Users)Session["CurUser"];
            }
            if (!IsPostBack)
            {
                MM.DAL.T_Users userDAL = new MM.DAL.T_Users();
                userModel = userDAL.GetCurUser(userModel.UserID);
                lbUserID.Text = userModel.UserID;
                txtUserName.Text = userModel.UserName;
                //txtTelephone.Text = userModel.Telephone;
                txtMobile.Text = userModel.Mobile;
                txtAddress.Text = userModel.Address;
                //txtRemark.Text = userModel.Remark;
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                userModel.UserName = txtUserName.Text.Trim();
                //userModel.Telephone = txtTelephone.Text.Trim();
                userModel.Mobile = txtMobile.Text.Trim();
                userModel.Address = txtAddress.Text.Trim();
                //userModel.Remark = txtRemark.Text.Trim();

                string strPD1 = txtNewPassWord1.Text.Trim();
                string strPD2 = txtNewPassWord2.Text.Trim();
                if (!string.IsNullOrEmpty(strPD1) && strPD1.Equals(strPD2))
                    userModel.PassWord = MM.Common.DESEncrypt.Encrypt(strPD1);

                //MM.DAL.T_Users userDAL = new MM.DAL.T_Users();
                //MM.DBUtility.DbHelperSql.ExecuteSql(string.Format("UPDATE T_Users SET PassWordinfo='{0}',UserName='{1}',Telephone='{2}',Mobile='{3}',Address='{4}',Remark='{5}' WHERE UserID='{6}'", userModel.PassWord, userModel.UserName, userModel.Telephone, userModel.Mobile, userModel.Address, userModel.Remark, userModel.UserID));
                MM.DBUtility.DbHelperSql.ExecuteSql(string.Format("UPDATE T_Users SET PassWordinfo='{0}',UserName='{1}',Mobile='{2}',Address='{3}' WHERE UserID='{4}'", userModel.PassWord, userModel.UserName, userModel.Mobile, userModel.Address, userModel.UserID));
                //userDAL.Update(userModel);
                MM.Common.Common.PageStartAlert(this.Page, "信息修改成功！");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
